home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / NETDEVIC.{3V < prev    next >
Text File  |  1999-09-17  |  14KB  |  458 lines

  1. /*
  2.  * INET        An implementation of the TCP/IP protocol suite for the LINUX
  3.  *        operating system.  INET is implemented using the  BSD Socket
  4.  *        interface as the means of communication with the user level.
  5.  *
  6.  *        Definitions for the Interfaces handler.
  7.  *
  8.  * Version:    @(#)dev.h    1.0.10    08/12/93
  9.  *
  10.  * Authors:    Ross Biro, <bir7@leland.Stanford.Edu>
  11.  *        Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12.  *        Corey Minyard <wf-rch!minyard@relay.EU.net>
  13.  *        Donald J. Becker, <becker@cesdis.gsfc.nasa.gov>
  14.  *        Alan Cox, <Alan.Cox@linux.org>
  15.  *        Bjorn Ekwall. <bj0rn@blox.se>
  16.  *
  17.  *        This program is free software; you can redistribute it and/or
  18.  *        modify it under the terms of the GNU General Public License
  19.  *        as published by the Free Software Foundation; either version
  20.  *        2 of the License, or (at your option) any later version.
  21.  *
  22.  *        Moved to /usr/include/linux for NET3
  23.  */
  24. #ifndef _LINUX_NETDEVICE_H
  25. #define _LINUX_NETDEVICE_H
  26.  
  27. #include <linux/config.h>
  28. #include <linux/if.h>
  29. #include <linux/if_ether.h>
  30. #include <linux/if_packet.h>
  31.  
  32. #include <asm/atomic.h>
  33.  
  34. #ifdef __KERNEL__
  35. #ifdef CONFIG_NET_PROFILE
  36. #include <net/profile.h>
  37. #endif
  38. #endif
  39.  
  40. /*
  41.  *    For future expansion when we will have different priorities. 
  42.  */
  43.  
  44. #define MAX_ADDR_LEN    7        /* Largest hardware address length */
  45.  
  46. /*
  47.  *    Compute the worst case header length according to the protocols
  48.  *    used.
  49.  */
  50.  
  51. #if !defined(CONFIG_AX25) && !defined(CONFIG_AX25_MODULE) && !defined(CONFIG_TR)
  52. #define LL_MAX_HEADER    32
  53. #else
  54. #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
  55. #define LL_MAX_HEADER    96
  56. #else
  57. #define LL_MAX_HEADER    48
  58. #endif
  59. #endif
  60.  
  61. #if !defined(CONFIG_NET_IPIP) && \
  62.     !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
  63. #define MAX_HEADER LL_MAX_HEADER
  64. #else
  65. #define MAX_HEADER (LL_MAX_HEADER + 48)
  66. #endif
  67.  
  68. /*
  69.  *    Network device statistics. Akin to the 2.0 ether stats but
  70.  *    with byte counters.
  71.  */
  72.  
  73. struct net_device_stats
  74. {
  75.     unsigned long    rx_packets;        /* total packets received    */
  76.     unsigned long    tx_packets;        /* total packets transmitted    */
  77.     unsigned long    rx_bytes;        /* total bytes received     */
  78.     unsigned long    tx_bytes;        /* total bytes transmitted    */
  79.     unsigned long    rx_errors;        /* bad packets received        */
  80.     unsigned long    tx_errors;        /* packet transmit problems    */
  81.     unsigned long    rx_dropped;        /* no space in linux buffers    */
  82.     unsigned long    tx_dropped;        /* no space available in linux    */
  83.     unsigned long    multicast;        /* multicast packets received    */
  84.     unsigned long    collisions;
  85.  
  86.     /* detailed rx_errors: */
  87.     unsigned long    rx_length_errors;
  88.     unsigned long    rx_over_errors;        /* receiver ring buff overflow    */
  89.     unsigned long    rx_crc_errors;        /* recved pkt with crc error    */
  90.     unsigned long    rx_frame_errors;    /* recv'd frame alignment error */
  91.     unsigned long    rx_fifo_errors;        /* recv'r fifo overrun        */
  92.     unsigned long    rx_missed_errors;    /* receiver missed packet    */
  93.  
  94.     /* detailed tx_errors */
  95.     unsigned long    tx_aborted_errors;
  96.     unsigned long    tx_carrier_errors;
  97.     unsigned long    tx_fifo_errors;
  98.     unsigned long    tx_heartbeat_errors;
  99.     unsigned long    tx_window_errors;
  100.     
  101.     /* for cslip etc */
  102.     unsigned long    rx_compressed;
  103.     unsigned long    tx_compressed;
  104. };
  105.  
  106. #ifdef CONFIG_NET_FASTROUTE
  107. struct net_fastroute_stats
  108. {
  109.     int        hits;
  110.     int        succeed;
  111.     int        deferred;
  112.     int        latency_reduction;
  113. };
  114. #endif
  115.  
  116. /* Media selection options. */
  117. enum {
  118.         IF_PORT_UNKNOWN = 0,
  119.         IF_PORT_10BASE2,
  120.         IF_PORT_10BASET,
  121.         IF_PORT_AUI,
  122.         IF_PORT_100BASET,
  123.         IF_PORT_100BASETX,
  124.         IF_PORT_100BASEFX
  125. };
  126.  
  127. #ifdef __KERNEL__
  128.  
  129. extern const char *if_port_text[];
  130.  
  131. #include <linux/skbuff.h>
  132.  
  133. struct neighbour;
  134. struct neigh_parms;
  135. struct sk_buff;
  136.  
  137. /*
  138.  *    We tag multicasts with these structures.
  139.  */
  140.  
  141. struct dev_mc_list
  142. {    
  143.     struct dev_mc_list    *next;
  144.     __u8            dmi_addr[MAX_ADDR_LEN];
  145.     unsigned char        dmi_addrlen;
  146.     int            dmi_users;
  147.     int            dmi_gusers;
  148. };
  149.  
  150. struct hh_cache
  151. {
  152.     struct hh_cache *hh_next;    /* Next entry                 */
  153.     atomic_t    hh_refcnt;    /* number of users                   */
  154.     unsigned short  hh_type;    /* protocol identifier, f.e ETH_P_IP */
  155.     int        (*hh_output)(struct sk_buff *skb);
  156.     rwlock_t    hh_lock;
  157.     /* cached hardware header; allow for machine alignment needs.        */
  158.     unsigned long    hh_data[16/sizeof(unsigned long)];
  159. };
  160.  
  161.  
  162. /*
  163.  *    The DEVICE structure.
  164.  *    Actually, this whole structure is a big mistake.  It mixes I/O
  165.  *    data with strictly "high-level" data, and it has to know about
  166.  *    almost every data structure used in the INET module.
  167.  *
  168.  *    FIXME: cleanup struct device such that network protocol info
  169.  *    moves out.
  170.  */
  171.  
  172. struct device
  173. {
  174.  
  175.     /*
  176.      * This is the first field of the "visible" part of this structure
  177.      * (i.e. as seen by users in the "Space.c" file).  It is the name
  178.      * the interface.
  179.      */
  180.     char            *name;
  181.  
  182.     /*
  183.      *    I/O specific fields
  184.      *    FIXME: Merge these and struct ifmap into one
  185.      */
  186.     unsigned long        rmem_end;    /* shmem "recv" end    */
  187.     unsigned long        rmem_start;    /* shmem "recv" start    */
  188.     unsigned long        mem_end;    /* shared mem end    */
  189.     unsigned long        mem_start;    /* shared mem start    */
  190.     unsigned long        base_addr;    /* device I/O address    */
  191.     unsigned int        irq;        /* device IRQ number    */
  192.     
  193.     /* Low-level status flags. */
  194.     volatile unsigned char    start;        /* start an operation    */
  195.     /*
  196.      * These two are just single-bit flags, but due to atomicity
  197.      * reasons they have to be inside a "unsigned long". However,
  198.      * they should be inside the SAME unsigned long instead of
  199.      * this wasteful use of memory..
  200.      */
  201.     unsigned long        interrupt;    /* bitops.. */
  202.     unsigned long        tbusy;        /* transmitter busy */
  203.     
  204.     struct device        *next;
  205.     
  206.     /* The device initialization function. Called only once. */
  207.     int            (*init)(struct device *dev);
  208.     void            (*destructor)(struct device *dev);
  209.  
  210.     /* Interface index. Unique device identifier    */
  211.     int            ifindex;
  212.     int            iflink;
  213.  
  214.     /*
  215.      *    Some hardware also needs these fields, but they are not
  216.      *    part of the usual set specified in Space.c.
  217.      */
  218.  
  219.     unsigned char        if_port;    /* Selectable AUI, TP,..*/
  220.     unsigned char        dma;        /* DMA channel        */
  221.  
  222.     struct net_device_stats* (*get_stats)(struct device *dev);
  223.     struct iw_statistics*    (*get_wireless_stats)(struct device *dev);
  224.  
  225.     /*
  226.      * This marks the end of the "visible" part of the structure. All
  227.      * fields hereafter are internal to the system, and may change at
  228.      * will (read: may be cleaned up at will).
  229.      */
  230.  
  231.     /* These may be needed for future network-power-down code. */
  232.     unsigned long        trans_start;    /* Time (in jiffies) of last Tx    */
  233.     unsigned long        last_rx;    /* Time of last Rx    */
  234.     
  235.     unsigned short        flags;    /* interface flags (a la BSD)    */
  236.     unsigned short        gflags;
  237.     unsigned        mtu;    /* interface MTU value        */
  238.     unsigned short        type;    /* interface hardware type    */
  239.     unsigned short        hard_header_len;    /* hardware hdr length    */
  240.     void            *priv;    /* pointer to private data    */
  241.     
  242.     /* Interface address info. */
  243.     unsigned char        broadcast[MAX_ADDR_LEN];    /* hw bcast add    */
  244.     unsigned char        pad;        /* make dev_addr aligned to 8 bytes */
  245.     unsigned char        dev_addr[MAX_ADDR_LEN];    /* hw address    */
  246.     unsigned char        addr_len;    /* hardware address length    */
  247.  
  248.     struct dev_mc_list    *mc_list;    /* Multicast mac addresses    */
  249.     int            mc_count;    /* Number of installed mcasts    */
  250.     int            promiscuity;
  251.     int            allmulti;
  252.     
  253.     /* For load balancing driver pair support */
  254.   
  255.     unsigned long        pkt_queue;    /* Packets queued    */
  256.     struct device        *slave;        /* Slave device        */
  257.  
  258.     /* Protocol specific pointers */
  259.     
  260.     void             *atalk_ptr;    /* AppleTalk link     */
  261.     void            *ip_ptr;    /* IPv4 specific data    */  
  262.     void                    *dn_ptr;        /* DECnet specific data */
  263.  
  264.     struct Qdisc        *qdisc;
  265.     struct Qdisc        *qdisc_sleeping;
  266.     struct Qdisc        *qdisc_list;
  267.     unsigned long        tx_queue_len;    /* Max frames per queue allowed */
  268.  
  269.     /* Pointers to interface service routines.    */
  270.     int            (*open)(struct device *dev);
  271.     int            (*stop)(struct device *dev);
  272.     int            (*hard_start_xmit) (struct sk_buff *skb,
  273.                             struct device *dev);
  274.     int            (*hard_header) (struct sk_buff *skb,
  275.                         struct device *dev,
  276.                         unsigned short type,
  277.                         void *daddr,
  278.                         void *saddr,
  279.                         unsigned len);
  280.     int            (*rebuild_header)(struct sk_buff *skb);
  281. #define HAVE_MULTICAST             
  282.     void            (*set_multicast_list)(struct device *dev);
  283. #define HAVE_SET_MAC_ADDR           
  284.     int            (*set_mac_address)(struct device *dev,
  285.                            void *addr);
  286. #define HAVE_PRIVATE_IOCTL
  287.     int            (*do_ioctl)(struct device *dev,
  288.                         struct ifreq *ifr, int cmd);
  289. #define HAVE_SET_CONFIG
  290.     int            (*set_config)(struct device *dev,
  291.                           struct ifmap *map);
  292. #define HAVE_HEADER_CACHE
  293.     int            (*hard_header_cache)(struct neighbour *neigh,
  294.                              struct hh_cache *hh);
  295.     void            (*header_cache_update)(struct hh_cache *hh,
  296.                                struct device *dev,
  297.                                unsigned char *  haddr);
  298. #define HAVE_CHANGE_MTU
  299.     int            (*change_mtu)(struct device *dev, int new_mtu);
  300.  
  301.     int            (*hard_header_parse)(struct sk_buff *skb,
  302.                              unsigned char *haddr);
  303.     int            (*neigh_setup)(struct device *dev, struct neigh_parms *);
  304.     int            (*accept_fastpath)(struct device *, struct dst_entry*);
  305.  
  306. #ifdef CONFIG_NET_FASTROUTE
  307.     /* Really, this semaphore may be necessary and for not fastroute code;
  308.        f.e. SMP??
  309.      */
  310.     int            tx_semaphore;
  311. #define NETDEV_FASTROUTE_HMASK 0xF
  312.     /* Semi-private data. Keep it at the end of device struct. */
  313.     struct dst_entry    *fastpath[NETDEV_FASTROUTE_HMASK+1];
  314. #endif
  315. };
  316.  
  317.  
  318. struct packet_type 
  319. {
  320.     unsigned short        type;    /* This is really htons(ether_type).    */
  321.     struct device        *dev;    /* NULL is wildcarded here        */
  322.     int            (*func) (struct sk_buff *, struct device *,
  323.                      struct packet_type *);
  324.     void            *data;    /* Private to the packet type        */
  325.     struct packet_type    *next;
  326. };
  327.  
  328.  
  329. #include <linux/interrupt.h>
  330. #include <linux/notifier.h>
  331.  
  332. extern struct device        loopback_dev;        /* The loopback */
  333. extern struct device        *dev_base;        /* All devices */
  334. extern struct packet_type     *ptype_base[16];    /* Hashed types */
  335. extern int            netdev_dropping;
  336. extern int            net_cpu_congestion;
  337.  
  338. extern struct device    *dev_getbyhwaddr(unsigned short type, char *hwaddr);
  339. extern void        dev_add_pack(struct packet_type *pt);
  340. extern void        dev_remove_pack(struct packet_type *pt);
  341. extern struct device    *dev_get(const char *name);
  342. extern struct device    *dev_alloc(const char *name, int *err);
  343. extern int        dev_alloc_name(struct device *dev, const char *name);
  344. extern int        dev_open(struct device *dev);
  345. extern int        dev_close(struct device *dev);
  346. extern int        dev_queue_xmit(struct sk_buff *skb);
  347. extern void        dev_loopback_xmit(struct sk_buff *skb);
  348. extern int        register_netdevice(struct device *dev);
  349. extern int        unregister_netdevice(struct device *dev);
  350. extern int         register_netdevice_notifier(struct notifier_block *nb);
  351. extern int        unregister_netdevice_notifier(struct notifier_block *nb);
  352. extern int        dev_new_index(void);
  353. extern struct device    *dev_get_by_index(int ifindex);
  354. extern int        dev_restart(struct device *dev);
  355.  
  356. typedef int gifconf_func_t(struct device * dev, char * bufptr, int len);
  357. extern int        register_gifconf(unsigned int family, gifconf_func_t * gifconf);
  358. extern __inline__ int unregister_gifconf(unsigned int family)
  359. {
  360.     return register_gifconf(family, 0);
  361. }
  362.  
  363. #define HAVE_NETIF_RX 1
  364. extern void        netif_rx(struct sk_buff *skb);
  365. extern void        net_bh(void);
  366. extern int        dev_get_info(char *buffer, char **start, off_t offset, int length, int dummy);
  367. extern int        dev_ioctl(unsigned int cmd, void *);
  368. extern int        dev_change_flags(struct device *, unsigned);
  369. extern void        dev_queue_xmit_nit(struct sk_buff *skb, struct device *dev);
  370.  
  371. extern void        dev_init(void);
  372.  
  373. extern int        netdev_nit;
  374.  
  375. /* Locking protection for page faults during outputs to devices unloaded during the fault */
  376.  
  377. extern atomic_t        dev_lockct;
  378.  
  379. /*
  380.  *    These two don't currently need to be atomic
  381.  *    but they may do soon. Do it properly anyway.
  382.  */
  383.  
  384. extern __inline__ void  dev_lock_list(void)
  385. {
  386.     atomic_inc(&dev_lockct);
  387. }
  388.  
  389. extern __inline__ void  dev_unlock_list(void)
  390. {
  391.     atomic_dec(&dev_lockct);
  392. }
  393.  
  394. /*
  395.  *    This almost never occurs, isn't in performance critical paths
  396.  *    and we can thus be relaxed about it. 
  397.  *
  398.  *    FIXME: What if this is being run as a real time process ??
  399.  *        Linus: We need a way to force a yield here ?
  400.  *
  401.  *    FIXME: Though dev_lockct is atomic varible, locking procedure
  402.  *        is not atomic.
  403.  */
  404.  
  405. extern __inline__ void dev_lock_wait(void)
  406. {
  407.     while (atomic_read(&dev_lockct)) {
  408.         current->counter = 0;
  409.         schedule();
  410.     }
  411. }
  412.  
  413. extern __inline__ void dev_init_buffers(struct device *dev)
  414. {
  415.     /* DO NOTHING */
  416. }
  417.  
  418. /* These functions live elsewhere (drivers/net/net_init.c, but related) */
  419.  
  420. extern void        ether_setup(struct device *dev);
  421. extern void        fddi_setup(struct device *dev);
  422. extern void        tr_setup(struct device *dev);
  423. extern void        tr_freedev(struct device *dev);
  424. extern int        ether_config(struct device *dev, struct ifmap *map);
  425. /* Support for loadable net-drivers */
  426. extern int        register_netdev(struct device *dev);
  427. extern void        unregister_netdev(struct device *dev);
  428. extern int        register_trdev(struct device *dev);
  429. extern void        unregister_trdev(struct device *dev);
  430. /* Functions used for multicast support */
  431. extern void        dev_mc_upload(struct device *dev);
  432. extern int         dev_mc_delete(struct device *dev, void *addr, int alen, int all);
  433. extern int        dev_mc_add(struct device *dev, void *addr, int alen, int newonly);
  434. extern void        dev_mc_discard(struct device *dev);
  435. extern void        dev_set_promiscuity(struct device *dev, int inc);
  436. extern void        dev_set_allmulti(struct device *dev, int inc);
  437. extern void        netdev_state_change(struct device *dev);
  438. /* Load a device via the kmod */
  439. extern void        dev_load(const char *name);
  440. extern void        dev_mcast_init(void);
  441. extern int        netdev_register_fc(struct device *dev, void (*stimul)(struct device *dev));
  442. extern void        netdev_unregister_fc(int bit);
  443. extern int        netdev_dropping;
  444. extern int        netdev_max_backlog;
  445. extern atomic_t        netdev_rx_dropped;
  446. extern unsigned long    netdev_fc_xoff;
  447. #ifdef CONFIG_NET_FASTROUTE
  448. extern int        netdev_fastroute;
  449. extern int        netdev_fastroute_obstacles;
  450. extern void        dev_clear_fastroute(struct device *dev);
  451. extern struct net_fastroute_stats dev_fastroute_stat;
  452. #endif
  453.  
  454.  
  455. #endif /* __KERNEL__ */
  456.  
  457. #endif    /* _LINUX_DEV_H */
  458.